var teacherid = getQueryVariable('techerid');
jQuery(document).ready(function() {
	$('#kit-search-more').on('click', function() {
		$('.kit-search-mored').toggle();
	});
	
	var col = [ 
	{
		title:'时间段',
		field:'name',
		align: 'center',
		valign: 'middle'
	},
	{
		title:'周一',
		align: 'center',
		valign: 'middle',
		formatter:function(value,row,index){
			return '<div id="div_'+row.id+'_1"><input id="'+row.id+'_1" timeid="'+row.id+'" weekid="1" type="checkbox" disabled="disabled">&nbsp;&nbsp;</div>';
		}
	},
	{
		title:'周二',
		align: 'center',
		valign: 'middle',
		formatter:function(value,row,index){
			return '<div id="div_'+row.id+'_2"><input id="'+row.id+'_2" timeid="'+row.id+'" weekid="2" type="checkbox" disabled="disabled">&nbsp;&nbsp;</div>';
		}
	},
	{
		title:'周三',
		align: 'center',
		valign: 'middle',
		formatter:function(value,row,index){
			return '<div id="div_'+row.id+'_3"><input id="'+row.id+'_3" timeid="'+row.id+'" weekid="3" type="checkbox" disabled="disabled">&nbsp;&nbsp;</div>';
		}
	},
	{
		title:'周四',
		align: 'center',
		valign: 'middle',
		formatter:function(value,row,index){
			return '<div id="div_'+row.id+'_4"><input id="'+row.id+'_4" timeid="'+row.id+'" weekid="4" type="checkbox" disabled="disabled">&nbsp;&nbsp;</div>';
		}
	},
	{
		title:'周五',
		align: 'center',
		valign: 'middle',
		formatter:function(value,row,index){
			return '<div id="div_'+row.id+'_5"><input id="'+row.id+'_5" timeid="'+row.id+'" weekid="5" type="checkbox" disabled="disabled">&nbsp;&nbsp;</div>';
		}
	},
	{
		title:'周六',
		align: 'center',
		valign: 'middle',
		formatter:function(value,row,index){
			return '<div id="div_'+row.id+'_6"><input id="'+row.id+'_6" timeid="'+row.id+'" weekid="6" type="checkbox" disabled="disabled">&nbsp;&nbsp;</div>';
		}
	},
	{
		title:'周日',
		align: 'center',
		valign: 'middle',
		formatter:function(value,row,index){
			return '<div id="div_'+row.id+'_7"><input id="'+row.id+'_7" timeid="'+row.id+'" weekid="7"timeid="'+row.id+'" weekid=""  type="checkbox" disabled="disabled" >&nbsp;&nbsp;</div>';
		}
	}];

	//------------------------------------------加载列表
	$('#_table').bootstrapTable({
		url:baseUrl+'/periods',
		'method': "GET",
		locale: 'zh-CN',
		detailView: false,
		sidePagination: "server", //服务端处理分页
		striped: true,//隔行变色
		undefinedText: "",
		pagination: true,
		singleSelect: false,
		pageSize: 200,//pageList[0],
		cache: false, //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
		pageNumber: 1,
//		pageList: pageList,
		search: false, //不显示 搜索框
		uniqueId: "id", //每一行的唯一标识，一般为主键列
		showColumns: false, //不显示下拉框（选择显示的列）
		undefinedText: '',
		columns: col,
		queryParams: function(params) {
			return {
				pageNum: this.pageNumber,
				pageSize: this.pageSize,
				sortOrder: params.order
			}
		},
		onLoadSuccess:function(){
			loaddatas();
		}
	});

})
var loaddatas=function(){
    $.get(baseUrl + '/teacherPeriods/used', {
        teacherid: teacherid
    }, function(data) {
        // console.log(data.rows.length);
        datas = data.data;
        for(var i = 0; i < datas.length; i++){
            var htm = '';
            var obi = datas[i];
            var checkid = '';
            for(var j = 0; j < obi.length; j++){
                var obj = obi[j];
                var msg = obj.status;
                checkid=obj.checkid;

                switch(msg) {
                    case '保留':
                        htm += '<input id="' + obj.checkid + '" objid="' + obj.id + '" weekid="' + obj.week + '"name="old" type="checkbox" checked>&nbsp;&nbsp;' +
                            '<font color="greenyellow">' + obj.useMsg + '</font><br/>';
                        break;
                    case '预留':
                        htm += '<input id="' + obj.checkid + '" objid="' + obj.id + '" weekid="' + obj.week + '"name="old" type="checkbox" checked>&nbsp;&nbsp;' + obj.useMsg+'<br/>';
                        break;
                    case '占用':
                        htm += '<input id="' + obj.checkid + '" perodid="' + obj.id + '" objid="' + obj.id + '" weekid="' + obj.week + '"name="old" type="checkbox" checked>&nbsp;&nbsp;' +
                            '<font color="#EA2A31">' + obj.useMsg + '</font><br/>';
                        break;
                    case '试听':
                        htm += '<input id="' + obj.checkid + '" objid="' + obj.id + '" weekid="' + obj.week + '"name="old" type="checkbox" checked>&nbsp;&nbsp;' +
                            '<font color="#F01EEF">' + obj.useMsg + '</font><br/>';
                        break;
                    default:
                        htm += '<input id="' + obj.checkid + '" perodid="' + obj.id + '" type="checkbox">&nbsp;&nbsp;' + obj.useMsg;
                        // htm += '<input id="' + obj.checkid + '" objid="' + obj.id + '" weekid="' + obj.week + '"name="old" type="checkbox">&nbsp;&nbsp;' + obj.useMsg;
                        // htm += '<br/><input id="' + obj.checkid + '" objid="' + obj.id + '" weekid="' + obj.week + '"name="retention" type="checkbox">&nbsp;&nbsp;保留时段';
                        break;
                }
            }
            $('#div_' + checkid).html(htm);
            $('#div_' + checkid).parent().css("background-color", '#9ACCF7');
        }
    });

}
var callback_save=function(){
	var objs=[];
	var news=$('input:checkbox:checked').each(function(i){
		objs.push($(this).attr('perodid'));
	});	
	return objs;
}

